1. Field of Art
The present invention generally relates to the field of digital information processing, and more specifically, to analyzing and modifying computer programs.
2. Background of the Invention
Computer programmers often wish to be able to identify portions of a computer program with given properties and to take actions on the identified portions. For example, a programmer might be interested in identifying classes having certain names and inheritance relationships, such as all classes having names starting with the letter ‘c’ that are second-level children (i.e., children of children) of classes with a given name. As another example, a programmer might be interested in identifying and modifying code for refactoring purposes, such as changing a method with signature “ClassA::GetWidget(int)” to accept two arguments instead of one, and thus to have the signature “ClassA::GetWidget(int, int).” In this example, in order to avoid breaking calling code it is important to change not only the signature of the method in its declaration, but also to appropriately change all code that also calls the method, a non-trivial operation.
The properties of interest can become very complex, particularly in the case of complex languages such as C++ that support features such as object oriented programming, multiple inheritance, friend functions, class and function templates, and so forth. For example, it can be difficult to distinguish non-member declarations within the body of a class, such as “friend void f(int),” from true member declarations such as “virtual void f(int a).” It is even more difficult to distinguish the properties of the function solely from the code used to call it, such as “f(3),” without further analysis of the context in which it is called. Similarly, when refactoring calls to ClassA::GetWidget(int) to accept two parameters rather than one, the presence of another class, ClassB, with a similar method GetWidget with the signature ClassB::GetWidget(int) would cause calls to a method “obj.GetWidget(3)” to be ambiguous without the additional context of the type of the object “obj”.
Further, for certain properties of interest, such as the inheritance relationships of different classes, the portions of code at issue (e.g., different classes) may be located far apart within a given code file, or may be in entirely different code files, rather than being localized for easy analysis. Thus, lexical analysis techniques that merely analyze the text of the program code are usually awkward to apply, and in many cases entirely incapable of identifying particular code of interest.